package com.example.jedis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author : frosty0804@gmail.com
 * @version : v1.0
 * @projectName : Learn
 * @className : JedisUtil
 * @description : TODO(Jedis工具类)
 * @date : 2020/3/26 16:53
 */
@Component
public class JedisUtil {

    @Autowired
    private JedisPool jedisPool;

    /**
     * 获得jedis对象
     */
    public Jedis getJedis() {
        return jedisPool.getResource();
    }

    /**
     * 释放jedis资源
     */
    public void close(Jedis jedis) {
        if (jedis != null) {
            jedis.close();
        }
    }

}
